﻿<html>
  <head>
    <meta name="GENERATOR" content="BLOCKNOTE.NET"/>
    <meta name="source"/>
    <basefont face="Verdana" size="2"/>
    <meta name="generator" content="h-smile:richtext"/>
  </head>
<body>
  <h1>Array object</h1>
  <p>Represents indexed vector (array) of values.</p>
  <dl>
    <h2>Properties</h2>
    <dt>length</dt>
    <dd>- <em>integer</em>, number of items in the array. Read/write property.</dd>
    <dt>[index]</dt>
    <dd><strong>- </strong><em>value</em>, element of the array at the <em>index</em> position, Read-write index accessor. Zero-based index.</dd>
    <dt>[begin..end]</dt>
    <dd><strong>- </strong><em>integers</em>, zero-based indexes of first and last element of the range. Returns slice of vector contains elements from <em>start</em> index and up to but not included <em>end</em> index. <em>Begin</em> or/and <em>end</em> are optional. If begin is ommited then it is assumed to be 0, if end - <em>length</em> is used as an end value.</dd>
    <dt>first</dt>
    <dd>- <em>value</em> | <em>undefined</em>, first element of the array, if any.</dd>
    <dt>last</dt>
    <dd>- <em>value</em> | <em>undefined</em>, last element of the array, if any.</dd>
    <h2>Methods</h2>
    <dt>Array</dt>
    <dd><strong>([value1 [, value2 [, ... valueN ]]])</strong>
      <p>Creates new array object from arguments provided. Use as <br/>var a = new Array(...);</p></dd>
    <dt>toLocaleString</dt>
    <dd>
      <div><strong>()</strong> returns: string</div>
      <p>Returns string - comma separated list of values</p></dd>
    <dt>toString</dt>
    <dd>
      <div><strong>()</strong> returns: string</div>
      <p>Returns string - comma separated list of values</p></dd>
    <dt>valueOf</dt>
    <dd>
      <div><strong>()</strong> returns: string</div>
      <p>Same as <em>toString</em>.</p></dd>
    <dt>clone</dt>
    <dd>
      <div><strong>(</strong>[deep:true]<strong>) </strong>returns: array</div>
      <p>Returns brand new copy of the array. If <em>deep</em> === true then it does recursive, deep cloning.</p></dd>
    <dt>push</dt>
    <dd>
      <div><strong>([value1 [, value2 [, ... valueN ]]])</strong> returns: value</div>
      <p>Appends array by <em>values</em>. Returns last inserted element.</p></dd>
    <dt>shift</dt>
    <dd>
      <div><strong>()</strong> returns: value | undefined</div>
      <p>Removes first element of the array. Returns removed element.</p></dd>
    <dt>pop</dt>
    <dd>
      <div><strong>()</strong> returns: value | undefined</div>
      <p>Removes last element of the array. Returns removed element.</p></dd>
    <dt>unshift</dt>
    <dd>
      <div><strong>(value)</strong> returns: value | undefined</div>
      <p>Inserts value at first array position. Returns the value.</p></dd>
    <dt>concat</dt>
    <dd>
      <div><strong>([value1 [, value2 [, ... valueN ]]]) </strong>returns: array</div>
      <p>Appends array by <em>values</em>. Returns the array.</p></dd>
    <dt>join</dt>
    <dd>
      <div><strong>([delimeter])</strong> returns: string</div>
      <p>Returns string with all elements of the array separated by the <em>delimeter</em> or comma</p></dd>
    <dt>reverse</dt>
    <dd>
      <div><strong>()</strong> returns: array</div>
      <p>Reverses order of elements in the array in-place. Returns the array.</p></dd>
    <dt>slice</dt>
    <dd>
      <div><strong>(start[, end])</strong> returns: array | undefined</div>
      <p>Returns new array consisting from elements of the array from <em>start</em> up to but not including <em>end</em> index.</p></dd>
    <dt>splice</dt>
    <dd>
      <div><strong>(index, count [, element1, element2, ...] )</strong> returns: array</div>
      <p>This method:</p>
      <ol>
        <li>Removes <em>count</em> number of elements at <em>index</em>.</li>
        <li>Inserts element1, element2, ... at <em>index</em> position.</li>
        <li>returns removed elements as an array or empty array if <em>count</em> is zero.</li></ol></dd>
    <dt>sort</dt>
    <dd>
      <div><strong>( [compareFunction] )</strong> returns: array</div>
      <p>Sorts elements of the array in ascending order. If the <em>compareFunction</em> provided it is used for comparing elements during sort. В <em>compareFunction</em> shall accept two values in parameters and return -1, 0 or +1 as a result.</p></dd>
    <dt>indexOf</dt>
    <dd>
      <div><strong>( </strong><em>value</em> [, <em>notfound</em> = -1] <strong>)</strong> returns: int | <em>notfound</em></div>
      <p>Get index of the <em>value</em> in array. If the <em>value</em> is not found returns the <em>notfound</em> value (-1 by default).</p></dd>
    <dt>lastIndexOf</dt>
    <dd>
      <div><strong>( </strong><em>value</em> [, <em>notfound</em> = -1] <strong>)</strong> returns: int | <em>notfound</em></div>
      <p>Get last index of the <em>value</em> in array. If the <em>value</em> is not found returns the <em>notfound</em> value (-1 by default).</p></dd>
    <dt>remove</dt>
    <dd>
      <div><strong>( </strong><em>index</em>:int <strong>) </strong>returns: value | nothing</div>
      <p>Removes element at <em>index</em>. Returns removed element.</p></dd>
    <dt>removeByValue</dt>
    <dd>
      <div><strong>( </strong><em>value</em> <strong>) </strong>returns: value | nothing</div>
      <p>Tries to locate element by value in the array and removes it. Returns removed element.</p></dd>
    <dt>map</dt>
    <dd>
      <div><strong>(</strong> <em>callback</em>: function [, <em>thisObject</em>] <strong>)</strong> : array</div>
      <p>This method creates a new array with the result of calling a provided <em>callback</em> function on every element in this array. If <em>thisObject</em> is provided then the callback will have it as <em>this</em>.</p>
      <p>The callback function may accept following parameters: <code>callback(currentValue, index, array)</code> where:</p>
      <ul>
        <li><em>currentValue</em> is a value of array element at the <em>index</em> position;</li>
        <li><em>array</em> is the array to what this method applied.</li></ul>
      <p>The <em>map</em> method<span class="Apple-converted-space"/>does not mutate the array on which it is called.</p>
      <p>If the callback function ends with nothing (without explicit return) then the element will not go to resulting array (as when filter() method below returns false). Note: this a la filter() behavior is non standard.</p>
      <p>Example:</p>
      <pre>var numbers = [1, 2, 3];
var squares = numbers.map(:el:el*el); // make new array of
                                      // squares of numbers
                                      // in original array.
// squares will be [1, 4, 9] at this point.
</pre></dd>
    <dt>reduce</dt>
    <dd>
      <p><strong>(</strong> callback:function [, initialValue] <strong>)</strong> : value</p>
      <p>This method applies the function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.</p>
      <p>The callback function may accept following parameters: <code>callback(previousValue, currentValue, index, array)</code> where:</p>
      <ul>
        <li><em>previousValue</em> is either <em>initialValue</em> (on first run) or result of previous call of the callback function;</li>
        <li><em>currentValue</em> is a value of array element at the <em>index</em> position;</li>
        <li><em>array</em> is the array being scanned (reduced).</li></ul>
      <p>The method returns result of last <em>callback</em> invocation. The method<span class="Apple-converted-space"/>does not mutate the array on which it is called.</p>
      <p>Example, this fragment calculates sum of all elements in the array:</p>
      <pre>var total = [0, 1, 2, 3].reduce( :a, b: a + b );
// total is 6 at this point.
</pre></dd>
    <dt>filter</dt>
    <dd>
      <p><strong>(</strong> <em>callback</em>: function [, <em>thisObject</em>] <strong>)</strong> : array</p>
      <p>This method calls the <em>callback</em><span class="Apple-converted-space"/>function once for each element in the array, and constructs new array of all the values for which<span class="Apple-converted-space"/>the <em>callback</em> returns <em>true</em>.</p>The callback function may accept following parameters: <code>callback(currentValue, index, array)</code> where:
      <ul>
        <li><em>currentValue</em> is a value of array element at the <em>index</em> position;</li>
        <li><em>array</em> is the array to what this method applied.</li></ul>
      <p>The <em>filter</em> method<span class="Apple-converted-space"/>does not mutate the array on which it is called.</p>
      <p>Example, this code creates new array from elements of source array that are greater than 10:</p>
      <pre>var filtered = [12, 5, 8, 130, 44].filter(:el: el &gt; 10);
// filtered is [12, 130, 44] here
</pre></dd>
    <dt>find</dt>
    <dd><strong>( </strong><b>predicate</b>:function [, <b>thisArg</b>: object]<strong> )</strong> : (index:integer, element: any)
      <p>Calls predicate <i>function</i> for each element of the array until the predicate returns &quot;truthy&quot; value. Returns found element.</p>
			<p>The predicate is a function with the following signature: </p>
			<p><code>function (element:any [, index:integer [, arr: array ]] ) : true | false</code></p>
			<p>where: </p>
			<ul><li><i>element</i> - element of the array&nbsp;</li><li><i>index</i> - index of the element in the array</li><li><i>arr</i> - the array the find() was called with.</li>
				</ul>
			<p>If <i>thisArg</i> is provided then it is passed as <i>this</i> variable into the predicate calls.</p>
			<p>The function returns as found index and as the element and so it can be used as:</p>
			
			<pre>var (i,v) = someArr.find(:el: el.id == &quot;foo&quot; ); // value and index, or
var v = someArr.find(:el: el.id == &quot;foo&quot; ); // just value</pre>
			
			</dd>
    <dt>some</dt>
    <dd><strong>( </strong><b>predicate</b>:function [, <b>thisArg</b>: object]<strong> )</strong> :  true | false <p> Calls <i>predicate</i> function for each element of the array until the predicate returns &quot;truthy&quot; value and returns <i>true</i>. If there is no element in the array for which the predicate is true then the method returns <i>false</i>.</p>
			<p>The predicate is a function with the following signature: </p>
			<p><code>function (element:any [, index:integer [, arr: array ]] ) : true | false</code></p>
			<p>where: </p>
			<ul><li><i>element</i> - element of the array&nbsp;</li><li><i>index</i> - index of the element in the array</li><li><i>arr</i> - the array the find() was called with.</li>
				</ul>
			<p>If <i>thisArg</i> is provided then it is passed as <i>this</i> variable into the predicate calls.</p>
      </dd>
    <dt>every</dt>
    <dd><strong>( </strong><b>predicate</b>:function [, <b>thisArg</b>: object]<strong> )</strong> :  true | false <p> Returns <i>true</i> if  for each element in the array&nbsp;<i>predicate</i> is&nbsp;<i>true</i>. If there is any element in the array for which the <i>predicate</i> is <i>false</i> the method returns&nbsp;<i>false</i>.</p>
			<p>The predicate is a function with the following signature: </p>
			<p><code>function (element:any [, index:integer [, arr: array ]] ) : true | false</code></p>
			<p>where: </p>
			<ul><li><i>element</i> - element of the array&nbsp;</li><li><i>index</i> - index of the element in the array</li><li><i>arr</i> - the array the find() was called with.</li>
				</ul>
			<p>If <i>thisArg</i> is provided then it is passed as <i>this</i> variable into the predicate calls.</p>
      </dd>
    <dt>addObserver</dt>
    <dd><strong>( observer</strong>:function<strong> )</strong> : undefined
      <p>Attaches observer to the array - function that is called when the array changes. The observer here is a function that has following signature:</p>
      <p><code>function observer(changeDefinition) {}</code> where changeDefinition is tuple having following fields:</p>
      <ul>
        <li><code>[0]</code> - symbol, one of:<code>#add-range</code> (one or many elements added), <code>#update-range</code> (one or many elements changed) or <code>#delete-range</code> (elements were deleted);</li>
        <li><code>[1]</code> - array, the object that property was changed;</li>
        <li><code>[2]</code> - integer, range start, index of first changed elements;</li>
        <li><code>[3]</code> - integer, range end (exclusive);</li></ul></dd>
    <dt>removeObserver</dt>
    <dd><strong>( observer</strong>:function<strong> )</strong> : undefined
      <p>Detaches given observer function from the array.</p></dd></dl>
</body>
</html>